/*     */ package com.waveset.adapter;
/*     */ 
/*     */ import com.sun.idm.logging.trace.Trace;
/*     */ import com.sun.idm.logging.trace.TraceManager;
/*     */ import com.waveset.adapter.ActiveSync;
/*     */ import com.waveset.adapter.ActiveSyncUtil;
/*     */ import com.waveset.adapter.ResourceAdapterBase;
/*     */ import com.waveset.adapter.iapi.IAPI;
/*     */ import com.waveset.adapter.iapi.IAPIException;
/*     */ import com.waveset.adapter.iapi.IAPIFactory;
/*     */ import com.waveset.object.GenericObject;
/*     */ import com.waveset.object.Resource;
/*     */ import com.waveset.object.Syntax;
/*     */ import com.waveset.object.WSUser;
/*     */ import com.waveset.object.WavesetResult;
/*     */ import com.waveset.util.WavesetException;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ public class SkeletonActiveSyncResourceAdapter extends ResourceAdapterBase
/*     */   implements ActiveSync
/*     */ {
/*     */   public static final String code_id = "$Id: SkeletonActiveSyncResourceAdapter.java,v 1.12 2008/11/05 21:55:34 kd229373 Exp $";
/*     */   private static final String CLASS = "com.waveset.adapter.SkeletonActiveSyncResourceAdapter";
/*  65 */   private static final Trace TRACE = TraceManager.getTrace("com.waveset.adapter.SkeletonActiveSyncResourceAdapter");
/*     */ 
/*  70 */   private ActiveSyncUtil _util = null;
/*     */   public static final String RA_HOST = "host";
/*     */   public static final String RA_PORT = "port";
/*     */   public static final String RA_USER = "User";
/*     */   public static final String RA_PASSWORD = "Password";
/*     */   public static final String RESOURCE_NAME = "Skeleton ActiveSync";
/*     */   public static final String RESOURCE_TYPE = "Skeleton ActiveSync";
/* 120 */   static final String prototypeXml = "<Resource name='Skeleton ActiveSync'\n          class='com.waveset.adapter.SkeletonActiveSyncResourceAdapter'\n          typeString='Skeleton ActiveSync'\n          typeDisplayString='Skeleton ActiveSync'\n          syncSource='true'\n          facets='activesync'>\n  <ResourceAttributes>\n    <ResourceAttribute name='host'\n                       displayName='com.waveset.adapter.RAMessages:RESATTR_HOST'\n                       type='" + Syntax.STRING.getName() + "'\n" + "                       multi='false'\n" + "                       description='" + "com.waveset.adapter.RAMessages:RESATTR_HELP_313" + "'/>\n" + "    <ResourceAttribute name='" + "port" + "'\n" + "                       displayName='" + "com.waveset.adapter.RAMessages:RESATTR_PORT" + "'\n" + "                       type='" + Syntax.STRING.getName() + "'\n" + "                       multi='false'\n" + "                       description='" + "com.waveset.adapter.RAMessages:RESATTR_HELP_311" + "'\n" + "                       value='1234' />\n" + "    <ResourceAttribute name='" + "User" + "'\n" + "                       displayName='" + "com.waveset.adapter.RAMessages:RESATTR_USER" + "'\n" + "                       type='" + Syntax.STRING.getName() + "'\n" + "                       multi='false'\n" + "                       description='" + "com.waveset.adapter.RAMessages:RESATTR_HELP_294" + "'/>\n" + "    <ResourceAttribute name='" + "Password" + "'\n" + "                       displayName='" + "com.waveset.adapter.RAMessages:RESATTR_PASSWORD" + "'\n" + "                       type='" + Syntax.STRING.getName() + "'\n" + "                       multi='false'\n" + "                       description='Password for user set above'/>\n" + "    <ResourceAttribute name='Proxy Administrator' displayName='com.waveset.adapter.RAMessages:RESATTR_PROXY_ADMINISTRATOR' type='string' multi='false' value='Configurator'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_30'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Input Form' displayName='com.waveset.adapter.RAMessages:RESATTR_FORM' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_26'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Pre-Poll Workflow' displayName='com.waveset.adapter.RAMessages:RESATTR_PREPOLL_WORKFLOW' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_PREPOLL_WORKFLOW_HELP'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Post-Poll Workflow' displayName='com.waveset.adapter.RAMessages:RESATTR_POSTPOLL_WORKFLOW' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_POSTPOLL_WORKFLOW_HELP'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Archives' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_ARCHIVES' type='string' multi='false'  value='3'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_ARCHIVES'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Age Length' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_LOG_AGE' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_LOG_AGE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Age Unit' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_LOG_AGE_UNIT' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_LOG_AGE_UNIT'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Log Level' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_LEVEL' type='string' multi='false' value='2'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_27'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Log File Path' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_PATH' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_28'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Log File Size' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_SIZE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_29'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Scheduling Interval' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_INTERVAL' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_51'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Poll Every' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_INTERVAL_COUNT' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_52'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Polling Start Time' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_START_TIME' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_56'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Polling Start Date' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_START_DATE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_54'>\n    </ResourceAttribute>\n    <ResourceAttribute name='assignSourceOnCreate' displayName='com.waveset.adapter.RAMessages:RESATTR_ASSIGN_SOURCE_ON_CREATE' type='boolean' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_ASSIGN_SOURCE_ON_CREATE_HELP' facets='activesync' value='true'>\n    </ResourceAttribute>\n" + "    <ResourceAttribute name='processRule' displayName='com.waveset.adapter.RAMessages:RESATTR_PROCESS_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_PROCESS_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='correlationRule' displayName='com.waveset.adapter.RAMessages:RESATTR_CORRELATION_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_CORRELATION_RULE_HELP' facets='activesync' value='CORRELATION_RULE_NONE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='confirmationRule' displayName='com.waveset.adapter.RAMessages:RESATTR_CONFIRMATION_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_CONFIRMATION_RULE_HELP' facets='activesync' value='CONFIRMATION_RULE_NONE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='deleteRule' displayName='com.waveset.adapter.RAMessages:RESATTR_DELETE_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_DELETE_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='createUnmatched' displayName='com.waveset.adapter.RAMessages:RESATTR_CREATE_UNMATCHED' type='string' multi='false' value='true'\n      description='com.waveset.adapter.RAMessages:RESATTR_CREATE_UNMATCHED_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='resolveProcessRule' displayName='com.waveset.adapter.RAMessages:RESATTR_RESOLVE_PROCESS_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_RESOLVE_PROCESS_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='populateGlobal' displayName='com.waveset.adapter.RAMessages:RESATTR_POPULATE_GLOBAL' type='string' multi='false' value='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_POPULATE_GLOBAL_HELP' facets='activesync'>\n    </ResourceAttribute>\n" + "    <ResourceAttribute name='Name3'\n" + "                       displayName='Name3'\n" + "                       type='" + Syntax.STRING.getName() + "'\n" + "                       multi='false'\n" + "                       description='This is used only during active sync'\n" + "                       facets='activesync'/>\n" + "  </ResourceAttributes>\n" + "  <Template>\n" + "    <text>CN=</text>\n" + "    <AttrDef name='accountId'\n" + "             type='" + Syntax.STRING.getName() + "'/>\n" + "    <text>,o=someorg</text>\n" + "  </Template>\n" + "  <AccountAttributeTypes>\n" + "    <AccountAttributeType name='accountId'\n" + "                          mapName='change-value-here'\n" + "                          mapType='" + Syntax.STRING.getName() + "'\n" + "                          required='true'>\n" + "      <AttributeDefinitionRef>\n" + "        <ObjectRef type='AttributeDefinition' name='accountId'/>\n" + "      </AttributeDefinitionRef>\n" + "    </AccountAttributeType>\n" + "    <AccountAttributeType name='skeletonASAttribute'\n" + "                          mapName='attributeNameOnResource'\n" + "                          mapType='" + Syntax.STRING.getName() + "'\n" + "                          required='false'/>\n" + "  </AccountAttributeTypes>\n" + "</Resource>\n";
/*     */ 
/*     */   public static Resource staticCreatePrototypeResource()
/*     */     throws WavesetException
/*     */   {
/* 216 */     Resource res = new Resource(prototypeXml);
/*     */ 
/* 219 */     res.setStartupType("Manual");
/*     */ 
/* 223 */     res.disableFeature("CONTINUE_ON_ERROR");
/*     */ 
/* 225 */     return res;
/*     */   }
/*     */ 
/*     */   public Resource createPrototypeResource() throws WavesetException {
/* 229 */     return staticCreatePrototypeResource();
/*     */   }
/*     */ 
/*     */   public Object getAttributeValue(String name)
/*     */     throws WavesetException
/*     */   {
/* 237 */     return getResource().getResourceAttributeVal(name);
/*     */   }
/*     */ 
/*     */   public void setAttributeValue(String name, Object value)
/*     */     throws WavesetException
/*     */   {
/* 245 */     getResource().setResourceAttributeVal(name, value);
/*     */   }
/*     */ 
/*     */   public void init()
/*     */     throws Exception
/*     */   {
/* 255 */     String METHOD = "init";
/* 256 */     TRACE.entry1("init");
/*     */ 
/* 258 */     this._util = new ActiveSyncUtil(this);
/* 259 */     this._util.logString(2, "Initializing SkeletonActiveSync resource adapter.\n");
/*     */ 
/* 272 */     this._util.logString(2, "Done initializing SkeletonActiveSync resource adapter.\n");
/*     */ 
/* 275 */     TRACE.exit1("init");
/*     */   }
/*     */ 
/*     */   public void shutdown()
/*     */   {
/*     */   }
/*     */ 
/*     */   protected List getUpdateRows(Map lastProcessedRow)
/*     */   {
/* 300 */     return new ArrayList(0);
/*     */   }
/*     */ 
/*     */   protected int processUpdates(List list)
/*     */     throws WavesetException, IAPIException
/*     */   {
/* 312 */     String METHOD = "processUpdates";
/* 313 */     TRACE.entry2("processUpdates");
/*     */ 
/* 315 */     int numProcessed = 0;
/*     */ 
/* 317 */     if (list != null) {
/* 318 */       int listSize = list.size();
/* 319 */       this._util.logString(2, "processUpdates: " + listSize + " elements.\n");
/*     */ 
/* 324 */       int currentRowCount = 0;
/* 325 */       Iterator it = list.iterator();
/* 326 */       while ((it.hasNext()) && (!this._util.isStopRequested())) {
/* 327 */         Map userMap = (Map)it.next();
/* 328 */         currentRowCount++;
/*     */ 
/* 332 */         logUpdate(2, userMap, null);
/* 333 */         this._util.logString(2, "processing update " + currentRowCount + " of " + listSize + ".\n");
/*     */ 
/* 341 */         Map options = new HashMap();
/*     */ 
/* 346 */         String identity = (String)userMap.get("EMPLID");
/* 347 */         if (identity == null) {
/* 348 */           String message = "Missing required attribute EMPLID. This is a configuration problem.";
/*     */ 
/* 354 */           if (isFeatureEnabled("CONTINUE_ON_ERROR")) {
/* 355 */             this._util.logString(3, message);
/*     */ 
/* 357 */             continue;
/*     */           }
/* 359 */           WavesetException we = new WavesetException(message);
/* 360 */           TRACE.throwing2("processUpdates", we);
/* 361 */           throw we;
/*     */         }
/*     */ 
/* 367 */         String adminName = (String)userMap.get("AUDIT_OPRID");
/* 368 */         if (adminName != null) {
/* 369 */           options.put("RemoteAdminName", adminName);
/*     */         }
/*     */ 
/* 374 */         boolean wasDelete = false;
/* 375 */         if (userMap.get("isDeleted") != null)
/*     */         {
/* 378 */           options.put("deleteEventDetected", Boolean.TRUE);
/* 379 */           wasDelete = true;
/*     */         }
/*     */ 
/* 384 */         IAPI event = IAPIFactory.getIAPI(options, userMap, this);
/*     */ 
/* 388 */         if ((event == null) && (wasDelete))
/*     */         {
/* 392 */           this._util.logString(2, "Received delete for user " + identity + " not in IdM.  Ignoring.\n");
/*     */         }
/*     */ 
/* 398 */         if (event != null) {
/* 399 */           numProcessed++;
/* 400 */           event.setLogger(this._util.getLogger());
/* 401 */           WavesetResult result = event.submit();
/*     */ 
/* 403 */           logUpdate(2, userMap, result);
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 408 */     TRACE.exit2("processUpdates", numProcessed);
/* 409 */     return numProcessed;
/*     */   }
/*     */ 
/*     */   public int poll()
/*     */   {
/* 421 */     String METHOD = "poll";
/* 422 */     TRACE.entry1("poll");
/*     */ 
/* 424 */     int numProcessed = 0;
/*     */     try {
/* 426 */       IAPI prox = IAPIFactory.getIAPIUser(null, null, null, this);
/*     */ 
/* 431 */       Map lastUpdatedInfo = (Map)prox.getProperty("lastUpdated");
/*     */ 
/* 436 */       Map lastProcessedRow = ActiveSyncUtil.reconstituteEmptyStrings(lastUpdatedInfo);
/*     */ 
/* 438 */       List updates = getUpdateRows(lastProcessedRow);
/*     */ 
/* 440 */       if ((updates != null) && (updates.size() > 0)) {
/* 441 */         numProcessed = processUpdates(updates);
/*     */ 
/* 447 */         lastProcessedRow = (Map)updates.get(updates.size() - 1);
/*     */ 
/* 449 */         if (lastProcessedRow != null) {
/* 450 */           Map m = ActiveSyncUtil.reconstituteEmptyStrings(lastProcessedRow);
/* 451 */           prox.setProperty("lastUpdated", m);
/*     */         }
/*     */       }
/*     */ 
/* 455 */       Thread.sleep(30000L);
/*     */     }
/*     */     catch (Throwable th)
/*     */     {
/* 462 */       this._util.logResourceException("Error processing updates ", th, TRACE, "poll");
/*     */     }
/*     */ 
/* 468 */     TRACE.exit1("poll", numProcessed);
/* 469 */     return numProcessed;
/*     */   }
/*     */ 
/*     */   protected void logUpdate(int level, Map update, WavesetResult result)
/*     */   {
/* 477 */     String METHOD = "logUpdate";
/* 478 */     TRACE.entry2("logUpdate");
/*     */ 
/* 480 */     if ((update == null) || (this._util.getLogLevel() < level)) return;
/*     */ 
/* 482 */     List msgs = result != null ? result.getMessages() : null;
/* 483 */     List errs = result != null ? result.getErrors() : null;
/*     */ 
/* 485 */     StringBuffer sb = new StringBuffer();
/* 486 */     if (result == null) {
/* 487 */       sb.append("Starting update processing for resource ");
/* 488 */       sb.append(getResource().getName());
/* 489 */       sb.append('\n');
/* 490 */       this._util.logString(level, sb.toString());
/* 491 */       sb.setLength(0);
/*     */     }
/*     */ 
/* 494 */     ActiveSyncUtil.mapToStringBuffer(update, sb);
/* 495 */     ActiveSyncUtil.listToStringBuffer(errs, sb);
/* 496 */     ActiveSyncUtil.listToStringBuffer(msgs, sb);
/*     */     try
/*     */     {
/* 499 */       this._util.logString(level, sb.toString());
/*     */     } catch (Throwable th) {
/* 501 */       System.out.println("SkeletonActiveSync Resource adapter. Error writing log: " + th.toString());
/*     */     }
/*     */ 
/* 505 */     if (result != null) {
/* 506 */       sb.setLength(0);
/* 507 */       sb.append("End update processing for resource ");
/* 508 */       sb.append(getResource().getName());
/* 509 */       sb.append('\n');
/* 510 */       this._util.logString(level, sb.toString());
/*     */     }
/*     */ 
/* 513 */     TRACE.exit2("logUpdate");
/*     */   }
/*     */ 
/*     */   public WavesetResult checkCreateAccount(WSUser user)
/*     */     throws WavesetException
/*     */   {
/* 521 */     return null;
/*     */   }
/*     */ 
/*     */   public WavesetResult checkUpdateAccount(WSUser user)
/*     */     throws WavesetException
/*     */   {
/* 529 */     return null;
/*     */   }
/*     */ 
/*     */   public WavesetResult checkDeleteAccount(WSUser user)
/*     */     throws WavesetException
/*     */   {
/* 537 */     return null;
/*     */   }
/*     */ 
/*     */   public WavesetResult authenticate(HashMap loginInfo)
/*     */     throws WavesetException
/*     */   {
/* 545 */     return null;
/*     */   }
/*     */ 
/*     */   public GenericObject getFeatures()
/*     */   {
/* 556 */     String METHOD = "getFeatures";
/* 557 */     TRACE.entry1("getFeatures");
/*     */ 
/* 563 */     GenericObject genObj = new GenericObject();
/*     */ 
/* 568 */     if (supportsCaseInsensitiveAccountIds()) {
/* 569 */       genObj.put("account.CASE_INSENSITIVE_IDS", "account.CASE_INSENSITIVE_IDS");
/*     */     }
/*     */ 
/* 579 */     genObj.put("CONTINUE_ON_ERROR", "CONTINUE_ON_ERROR");
/*     */ 
/* 584 */     if (TRACE.level3("getFeatures")) {
/* 585 */       TRACE.info(0L, "getFeatures", "\n" + genObj.toXml());
/*     */     }
/*     */ 
/* 588 */     TRACE.exit1("getFeatures");
/* 589 */     return genObj;
/*     */   }
/*     */ }

/* Location:           E:\IDM_Code\idmadapter.jar
 * Qualified Name:     com.waveset.adapter.SkeletonActiveSyncResourceAdapter
 * JD-Core Version:    0.6.0
 */